package com.example.myapplication.Fragment;

import android.app.Activity;
import android.os.Build;
import android.provider.UserDictionary;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import androidx.viewpager2.widget.ViewPager2;
import com.example.myapplication.*;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;
import com.xuexiang.xui.XUI;

import java.util.ArrayList;
import java.util.List;

public class main_fragment extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 初始化UI框架
        XUI.init(this.getApplication());
        // 开启UI框架调试日志
        XUI.initTheme(this);
        XUI.debug(true);
        //---------------------------------------以下是设置沉浸式状态栏的代码------------------------------
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
        //------------设置状态栏的字体颜色为黑色
        setAndroidNativeLightStatusBar(this, true);
        //------------------------------------------------------END-----------------------------------------------
        setContentView(R.layout.main_fragment);
        setupBottomNavigationBar();
    }
    private static void setAndroidNativeLightStatusBar(Activity activity, boolean dark) {
        View decor = activity.getWindow().getDecorView();
        if (dark) {
            decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        } else {
            decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        }
    }
    // 在 Activity 中设置底部导航栏
    private void setupBottomNavigationBar() {
        BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation_view);

        // 为每个选项创建对应的 Fragment
        final fragment_1 fragment1 = new fragment_1();
        final test fragment2 = new test();
//        final Fragment3 fragment3 = new Fragment3();
            //------------------------------------------------------------
        //------------------------------------------------------------

        //------------------------------------------------------------------------------------------
        // 设置底部导航栏的选项点击事件
        bottomNavigationView.setOnNavigationItemSelectedListener(
                new BottomNavigationView.OnNavigationItemSelectedListener() {
                    @Override
                    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                        if (item.getItemId() == R.id.navigation_item1) {
                            // 替换当前 Fragment 为 fragment1
                            getSupportFragmentManager().beginTransaction()
                                    .replace(R.id.fragment_container, fragment1)
                                    .commit();
                            return true;
                        } else if (item.getItemId() == R.id.navigation_item2) {
                            // 替换当前 Fragment 为 fragment2
                            getSupportFragmentManager().beginTransaction()
                                    .replace(R.id.fragment_container, fragment2)
                                    .commit();
                            return true;
                        } else if (item.getItemId() == R.id.navigation_item3) {
                            // 替换当前 Fragment 为 fragment3
                            getSupportFragmentManager().beginTransaction()
                                    .replace(R.id.fragment_container, fragment1)
                                    .commit();
                            return true;
                        }
                        return false;
                    }
                });

        // 初始加载第一个 Fragment
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.fragment_container, fragment1)
                .commit();
    }


}